<template>
  <div class="app-container">
    <eHeader :query="query" />
    <!--表格渲染-->
    <el-table v-loading="loading" :data="data" size="small" style="width: 100%;">
      <!-- <el-table-column prop="id" label="序号"/>-->
      <el-table-column prop="warehousename" :show-overflow-tooltip="true" label="仓库名称" />
      <el-table-column prop="warehouselocation" :show-overflow-tooltip="true" label="仓库地址" />
      <el-table-column prop="warehousedeptname" :show-overflow-tooltip="true" label="仓库归属" />
      <el-table-column prop="personname" :show-overflow-tooltip="true" label="仓库管理员" />
      <el-table-column prop="warehouseadministratorphone" :show-overflow-tooltip="true" label="联系方式" />
      <el-table-column :show-overflow-tooltip="true" label="仓库状态">
        <template slot-scope="scope">
          <span v-if="scope.row.state===1">在用</span>
          <span v-if="scope.row.state===0">停用</span>
        </template>
      </el-table-column>
      <el-table-column v-if="checkPermission(['ADMIN','TWAREHOUSE_ALL','TWAREHOUSE_EDIT','TWAREHOUSE_DELETE'])" label="操作" width="200px" align="center">
        <template slot-scope="scope">
          <edit v-permission="['ADMIN','TWAREHOUSE_ALL','TWAREHOUSE_DELETE']" :data="scope.row" :sup-this.sync="supThis" :is-view="true" :is-add="false" />
          <edit v-permission="['ADMIN','TWAREHOUSE_ALL','TWAREHOUSE_DELETE']" :data="scope.row" :sup-this.sync="supThis" :is-view="false" :is-add="false" />
          <el-popover
            :ref="scope.row.id"
            v-permission="['ADMIN','TWAREHOUSE_ALL','TWAREHOUSE_DELETE']"
            placement="top"
            width="180"
          >
            <p>确定删除本条数据吗？</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button>
              <el-button :loading="delLoading" type="primary" size="mini" @click="subDelete(scope.row.id)">确定</el-button>
            </div>
            <el-button slot="reference" type="danger" icon="el-icon-delete" size="mini" />
          </el-popover>
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <el-pagination
      :total="total"
      style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes"
      @size-change="sizeChange"
      @current-change="pageChange"
    />
  </div>
</template>

<script>
import checkPermission from '@/utils/permission'
import initData from '@/mixins/initData'
import { del } from '@/api/tWarehouse'
import eHeader from './module/header'
import edit from './module/edit'
export default {
  components: { eHeader, edit },
  mixins: [initData],
  data() {
    return {
      delLoading: false,
      supThis: this
    }
  },
  created() {
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    checkPermission,
    beforeInit() {
      this.url = 'api/tWarehouse'
      const sort = 'id,desc'
      this.params = { page: this.page, size: this.size, sort: sort }
      const query = this.query
      // const type = query.type
      // const value = query.value
      if (query.warehousename) {
        this.params['warehousename'] = query.warehousename
      }
      // if (type && value) { this.params[type] = value }
      return true
    },
    subDelete(id) {
      this.delLoading = true
      del(id).then(res => {
        this.delLoading = false
        this.$refs[id].doClose()
        this.init()
        this.$notify({
          title: '删除成功',
          type: 'success',
          duration: 2500
        })
      }).catch(err => {
        this.delLoading = false
        this.$refs[id].doClose()
        console.log(err)
      })
    }
  }
}
</script>

<style scoped>
</style>
